n, k = map(int, input().split())
a = list(map(int, input().split()))

def is_possible(mid):
    # 检查是否可以通过倒水操作使得所有瓶子的水量至少为mid
    extra = 0
    for i in range(n):
        color = i % k
        # 前面的瓶子可以向后倒水
        if a[i] >= mid:
            extra += a[i] - mid
        else:
            needed = mid - a[i]
            if extra >= needed:
                extra -= needed
            else:
                return False
    return True

left = min(a)
right = sum(a) // n
answer = left
while left <= right:
    mid = (left + right) // 2
    if is_possible(mid):
        answer = mid
        left = mid + 1
    else:
        right = mid - 1

print(answer)